#include "TWin.h"
#include "TScale9.h"
#include "../utils/Utils.h"
 


/***************************************************
 * TWin
 **************************************************/
TWin::TWin()
{
    m_nWinID = 0;  
    
}

TWin::~TWin(){
}

 

bool TWin::init(void){
    
    if(!TPanel::init()){
        return false;
    } 
  
    return true;
}




bool TWin::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent){
    
    CCPoint clickPos= pTouch->getLocation();
    
    
    CCPoint pos= getPosInTarget(clickPos, this);
    
    if(pos.x<0 || pos.x>getContentSize().width
       ||pos.y>0 || pos.y<-getContentSize().height  ){
        return false;
    }
     
    TPanel::ccTouchBegan(pTouch, pEvent);
  
    return true;
}

void TWin::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent)
{
    
    TPanel::ccTouchMoved(pTouch, pEvent);
}


void TWin::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent)
{
    
    TPanel::ccTouchEnded(pTouch, pEvent);
}
 

void TWin::procTuiEvent(const string& event,TPanelItem*){
    
    if(event=="closeWin"){
        if(this->getParent()){
            this->getParent()->removeChild(this, true);
        }
    }
}

void TWin::onShow(){
    if(getParent()){
        this->setX(getParent()->getContentSize().width/2-getContentSize().width/2);
        this->setY(getParent()->getContentSize().height/2-getContentSize().height/2);
    }
}

void TWin::onClose(){
    
}

 

